﻿using System;
using System.Collections.Generic;

using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using X.Web;

namespace X.WebSite.Admin.Msn
{
    public partial class Detail : AdminPage
    {
        int _MsnId
        {
            get
            {
                int msnId = 0;
                if (!string.IsNullOrEmpty(Request.QueryString["MsnId"]))
                    msnId = int.Parse(Request.QueryString["MsnId"]); return msnId;
            }
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                X.Entity.MsnInfo msnInfo = Bll.Msn.GetMsnInfo(_MsnId);
                txtMsnAccount.Text = msnInfo.MsnAccount;
                txtMsnUserName.Text = msnInfo.MsnUsername;
                chkIsAvailable.Checked = msnInfo.IsAvailable;
                ddlType.SelectedIndex = msnInfo.AccountType;
            }
        }

        protected void btnSubmit_Click(object sender, EventArgs e)
        {
            X.Entity.MsnInfo msnInfo;

            if (0 != _MsnId)
            {
                msnInfo = Bll.Msn.GetMsnInfo(_MsnId);

                msnInfo.MsnAccount = txtMsnAccount.Text;
                msnInfo.MsnUsername = txtMsnUserName.Text;
                msnInfo.IsAvailable = chkIsAvailable.Checked;
                msnInfo.AccountType = ddlType.SelectedIndex;

                Bll.Msn.Update(msnInfo);
            }
            else
            {
                msnInfo = new Entity.MsnInfo();

                msnInfo.MsnAccount = txtMsnAccount.Text;
                msnInfo.MsnUsername = txtMsnUserName.Text;
                msnInfo.IsAvailable = chkIsAvailable.Checked;
                msnInfo.AccountType = ddlType.SelectedIndex;

                Bll.Msn.Create(msnInfo);
            }

            Response.Redirect("List.aspx");
        }
    }
}